﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Biblioteca.fachada;
using Biblioteca.classesBasicas.pessoa;
using Desktop.views.cruds.crudsPessoa.crudFuncionario;


namespace Desktop.views.cruds.crudsPessoa.crudsFuncionario
{
    public partial class MenuFuncionario : Form
    {
        private TelaInicial telaInicial;
        private Fachada fachada = new Fachada();
        private List<Funcionario> listaFuncionario;
        private Funcionario funcionario = new Funcionario();

        public MenuFuncionario(TelaInicial telaInicial)
        {
            InitializeComponent();

            this.telaInicial = telaInicial;
            telaInicial.Hide();  
        }

        private void buttonCadastrar_Click(object sender, EventArgs e)
        {
            CadastroFuncionario cadastroFuncionario = new CadastroFuncionario(this);
            cadastroFuncionario.ShowDialog();
        }

        private void buttonSair_Click(object sender, EventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void MenuFuncionario_FormClosed(object sender, FormClosedEventArgs e)
        {
            telaInicial.Show();
            this.Dispose();
        }

        private void MenuFuncionario_Load(object sender, EventArgs e)
        {
            this.carregarGridViewFuncionario();
        }

        private void dataGridViewFuncionario_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex > -1)
            {
                DataGridViewRow row = this.dataGridViewFuncionario.Rows[e.RowIndex];

                funcionario.Id = row.Cells[0].Value.ToString();
                funcionario.Nome = row.Cells[1].Value.ToString();
                funcionario.Sexo = row.Cells[2].Value.ToString();
                funcionario.Idade = row.Cells[3].Value.ToString();
                funcionario.Rg = row.Cells[4].Value.ToString();
                funcionario.Cpf = row.Cells[5].Value.ToString();
                funcionario.Cargo = row.Cells[6].Value.ToString();
                funcionario.Salario = row.Cells[7].Value.ToString();

                AlterarRemoverFuncionario alterar = new AlterarRemoverFuncionario(this, funcionario);
                alterar.ShowDialog();
            }
        }


        public void carregarGridViewFuncionario()
        {
            listaFuncionario = fachada.listarFuncionario();

            dataGridViewFuncionario.Rows.Clear();
            dataGridViewFuncionario.ColumnCount = 8;
            dataGridViewFuncionario.ColumnHeadersVisible = true;
            dataGridViewFuncionario.AllowUserToAddRows = false;
                                               
            DataGridViewCellStyle columnHeaderStyle =
            new DataGridViewCellStyle();
            columnHeaderStyle.BackColor = Color.Aqua;
            columnHeaderStyle.Font =
                new Font("Verdana", 10, FontStyle.Bold);
            this.dataGridViewFuncionario.ColumnHeadersDefaultCellStyle =
                columnHeaderStyle;

            //dataGridViewFuncionario.DataSource = listaFuncionario;
            
            this.dataGridViewFuncionario.Columns[0].HeaderText = "ID";
            this.dataGridViewFuncionario.Columns[1].HeaderText = "NOME";
            this.dataGridViewFuncionario.Columns[2].HeaderText = "SEXO";
            this.dataGridViewFuncionario.Columns[3].HeaderText = "IDADE";
            this.dataGridViewFuncionario.Columns[4].HeaderText = "RG";
            this.dataGridViewFuncionario.Columns[5].HeaderText = "CPF";
            this.dataGridViewFuncionario.Columns[6].HeaderText = "CARGO";
            this.dataGridViewFuncionario.Columns[7].HeaderText = "SALARIO";

            foreach (Funcionario elemento in listaFuncionario)
            {
                dataGridViewFuncionario.Rows.Add(elemento.Id, elemento.Nome, elemento.Sexo, elemento.Idade, elemento.Rg, elemento.Cpf, elemento.Cargo, elemento.Salario);
            }  
        }       
     
    }
}
